/*
 * Copyright (c) 2009 John Pritchard, WTKX Project Group
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package wtkx.ps;

import com.google.protobuf.Message;
import java.net.MalformedURLException;
import java.net.URL;

public class Test 
    extends Object
    implements Consumer
{

    public Test(){
        super();
    }
    

    public void clientConnected(Client client){
        System.out.println("Connected> ");
    }
    public void clientDisconnected(Client client){
        System.out.println("Disconnected> ");
    }
    public boolean clientUpdate(Client client, Message m){
        Wtkx.Update wum = (Wtkx.Update)m;
        StringBuilder strbuf = new StringBuilder();
        strbuf.append("Received> ");
        strbuf.append(wum.getOp());
        if (wum.hasId()){
            strbuf.append(", id=");
            strbuf.append(wum.getId());
        }
        if (wum.hasAt()){
            strbuf.append(", at=");
            strbuf.append(wum.getAt());
        }
        if (wum.hasPath()){
            strbuf.append(", path=");
            strbuf.append(wum.getPath());
        }
        if (wum.hasUrl()){
            strbuf.append(", url=");
            strbuf.append(wum.getUrl());
        }
        if (wum.hasStart()){
            strbuf.append(", start=");
            strbuf.append(wum.getStart());
        }
        if (wum.hasEnd()){
            strbuf.append(", end=");
            strbuf.append(wum.getEnd());
        }
        if (wum.hasSearch()){
            strbuf.append(", search=");
            strbuf.append(wum.getSearch());
        }
        if (wum.hasWith()){
            strbuf.append(", with=");
            strbuf.append(wum.getWith());
        }
        if (wum.hasContent()){
            strbuf.append(", content=");
            strbuf.append(wum.getContent().toStringUtf8().replace('\n',' '));
        }
        System.out.println(strbuf.toString());
        return true;
    }


    public static void main(String[] argv){
        try {
            Client client = new Client();
            client.setSrc(argv[0]);
            client.setConsumer(new Test());
            client.init(null,null);
        }
        catch (Exception exc){
            exc.printStackTrace();
            System.exit(1);
        }
    }
}
